package com.lu.library.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import com.aigestudio.wheelpicker.widgets.WheelDatePicker
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.lu.library.R
import com.lu.library.databinding.DialogWheelBinding
import com.lu.library.databinding.DialogWheelDateBinding
import com.lu.library.ext.sp
import org.joda.time.DateTime
import java.util.Date

/**
 * 日期选择弹框
 */
class WheelDateDialog(context: Context,
                         var currentYear:Int,
                         var currentMonth:Int,
                         var currentDay:Int,
                        var yearStart:Int=1990,
                        var yearEnd:Int = DateTime.now().year,
                         val onSelectedCallback:(Int,Int,Int)->Unit): BottomSheetDialog(context) {


    private lateinit var binding: DialogWheelDateBinding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DialogWheelDateBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.tvCancel.setOnClickListener {
            dismiss()
        }
//        binding.wheelView.data = data
//        binding.wheelView.setOnItemSelectedListener { picker, data, position ->
//            currentIndex = position
//        }
//        binding.wheelView.setSelectedItemPosition(currentIndex,false)

//        binding.wheelView.setDebug(true)
        binding.wheelView.setYearFrame(yearStart,yearEnd)
//        binding.wheelView.yearEnd = yearEnd


        binding.wheelView.selectedDay = currentDay
        binding.wheelView.setYearAndMonth(currentYear,currentMonth)
        binding.wheelView.setAtmospheric(true)
        binding.wheelView.itemTextSize = 14.sp()
        binding.wheelView.selectedItemTextColor = Color.parseColor("#333333")
        binding.wheelView.setOnDateSelectedListener(object: WheelDatePicker.OnDateSelectedListener {
            override fun onDateSelected(picker: WheelDatePicker, date: Date) {

            }
        })
        binding.wheelView.selectedYear = currentYear
        binding.tvOk.setOnClickListener {
            onSelectedCallback(binding.wheelView.currentYear,binding.wheelView.currentMonth,binding.wheelView.currentDay)
            dismiss()
        }

    }


}